// ================================================================================
// 		File: PartyQuestionnaireSubject.cs
// 		Desc: 
//  
// 		Called by:   
//               
// 		Auth: chenwenzhi（）
// 		Date: 2016-06-27 21:47
// ================================================================================
// 		Change History
// ================================================================================
// 		Date:		Author:				Description:
// 		--------	--------			-------------------
//    
// ================================================================================
// 
// ================================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq; 
using System.Text;
using MySql.Data.MySqlClient;
using ZHDJ.Core;

namespace ZHDJ.Data.Models.Questionnaire
{
    /// <summary>
    /// 问卷题目
    /// </summary>   
    public class PartyQuestionnaireSubject 
    { 
		#region 属性
        /// <summary>
        /// ID
        /// </summary>
        public string ID { get; set; }
		
        /// <summary>
        /// 问卷ID
        /// </summary>
        public string QuestionnaireID { get; set; }
		
        /// <summary>
        /// 类型
        /// </summary>
        public string Category { get; set; }
		
        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 排序号
        /// </summary>
        public int OrderNo { get; set; }
        /// <summary>
        /// 状态
        /// </summary>
        public bool Enabled { get; set; }
        /// <summary>
        /// 创建用户
        /// </summary>
        public string CreateBy { get; set; }
		
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }
		
        /// <summary>
        /// 修改用户
        /// </summary>
        public string ModifyBy { get; set; }
		
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime? ModifyTime { get; set; }
		
		#endregion 

		#region 查询管理

		 public static DataSet GetGridData(int pageIndex, int pageSize,string questionnaireId ,string searchKey = "")
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize}
            };


            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS  data.ID,data.Enabled,data.OrderNo,data.QuestionnaireID,
data.Category,data.Title,data.CreateBy,data.CreateTime,data.ModifyBy,data.ModifyTime,
case Category when 1 then '多选' else '单选' end CategoryName
                        from tblPartyQuestionnaireSubject data
                        where 1=1 ");
            if (!string.IsNullOrEmpty(searchKey))
            {
                sb.Append(" and data.Title like ?key ");
                parameters.Add(
                    new MySqlParameter() { DbType = DbType.String, ParameterName = "key", Value = string.Format("%{0}%", searchKey) });
            }
            if (!string.IsNullOrEmpty(questionnaireId))
            {
                sb.Append(" and data.QuestionnaireID = ?QuestionnaireID ");
                parameters.Add(
                    new MySqlParameter() { DbType = DbType.String, ParameterName = "QuestionnaireID", Value = questionnaireId });
            }
            sb.Append(" order by data.OrderNo, data.CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray());
        }
		#endregion
    }
}
